/* Please refer to
  * http://www.gamedev.net/reference/articles/article1800.asp
  * for explanations
*/
var LGDSHexLocator = Class.create({
  initialize: function (height, baseLen) {
    this.xGlobal = -1;
    this.yGlobal = -1;
    this.height = height;
    this.baseLen = baseLen;
    this.yOffset = height / 2;
    this.xOffset = baseLen / 2;
    this.width = this.xOffset + baseLen;
  },
  // Return PosX[0] and PosY[1] in coord of the playground
  // Coord is from the bottom-left corner
  whereInPlayGround: function (x, y) {
    return new Array( x * (this.xOffset + this.baseLen) ,
		      y * this.height + (x * this.yOffset) );
  },
  setGlobals: function (x, y) {
    this.xGlobal = x;
    this.yGlobal = y;
  },
  local2global: function (x, y) {
    return new Array(this.xGlobal + x, this.yGlobal + y);
  },
  global2local: function (x, y) {
    return new Array(x - this.xGlobal, y - this.yGlobal);
  },
  // Is here good place for that ?
  // Sort tiles for the 3d Iso
  sortTo3dIso: function (tiles) {
    function sortTile (tileA, tileB) {
      if(tileA.y == tileB.y)
	return tileB.x - tileA.x;
      else
	return tileB.y - tileA.y;
    }
    tiles.sort(sortTile);
  }
});


// Repere Orthonormal
//return new Array( y * this.height + (x % 2) * this.yOffset, x * (this.xOffset + this.baseLen));